Skip to content

fix(chat): ignore Enter during IME composition to avoid duplicate send - #75

Open
sylitas wants to merge 1 commit into
formulahendry:mainfrom
sylitas:fix/ime-enter-duplicate-send
Open

sylitas wants to merge 1 commit into
formulahendry:mainfrom
sylitas:fix/ime-enter-duplicate-send

Conversation

@sylitas

@sylitas sylitas commented Oct 29, 2026

Copy link
Copy Markdown

Problem

On macOS with an IME-based keyboard layout (reproduced with the Vietnamese Telex input method, but the same applies to any CJK/IME input), a single Enter press is delivered to the chat input as two keydown events:

  1. the first one while the composition is still active (KeyboardEvent.isComposing === true, keyCode === 229),
  2. the second one after the composition has been committed.

The webview keydown handler treated both events as a "send":

Enter (isComposing = true)  -> handleSend()  -> promptInput.value = ''
IME composition commit      -> re-inserts the last composed word into the now empty textarea
Enter (isComposing = false) -> handleSend()  -> sends the leftover word alone

Result: every prompt that ends with a composed word is sent twice — the full prompt, plus a second message that only contains the duplicated last word (e.g. Hi em là ai followed by ai). Non-IME layouts (English) are unaffected because they never enter a composition state.

Fix

Ignore keydown events that are part of an IME composition:

promptInput.addEventListener('keydown', (e) => {
  if (e.isComposing || e.keyCode === 229) return;

The first (composing) event no longer sends, so the composition is committed normally into an intact textarea; the following post-composition event sends the full prompt exactly once. keyCode === 229 is kept as a fallback for IMEs that do not set isComposing.

No behavior change for non-IME input, and no need for a second Enter press.

Testing

  • npx tsc -p . --noEmit — passes
  • npx eslint src --max-warnings 0 — passes
  • Manual, macOS + Vietnamese Telex: typing a prompt whose last word is Vietnamese and pressing Enter now sends one message; before the patch it sent two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant